<html>
<head><meta charset="utf-8"><title>Add integer log2 function to std · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html">Add integer log2 function to std</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222204759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222204759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boscop <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222204759">(Jan 10 2021 at 04:11)</a>:</h4>
<p>I often need this function in my projects:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">ilog2</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">PrimInt</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">Unsigned</span><span class="o">&gt;</span><span class="p">(</span><span class="n">n</span>: <span class="nc">T</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">bits_minus_1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">u32</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="mi">8</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">bits_minus_1</span><span class="p">.</span><span class="n">saturating_sub</span><span class="p">(</span><span class="n">n</span><span class="p">.</span><span class="n">leading_zeros</span><span class="p">())</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I'm surprised that a function like this is not already in <code>std</code>, considering that <code>std</code> has float log2 functions.<br>
Could this function be added to std? :)</p>



<a name="222205382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222205382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222205382">(Jan 10 2021 at 04:31)</a>:</h4>
<p>There's some discussion at <a href="https://github.com/rust-lang/rust/issues/70887">https://github.com/rust-lang/rust/issues/70887</a> and <a href="https://github.com/rust-lang/rust/pull/70835">https://github.com/rust-lang/rust/pull/70835</a></p>



<a name="222214370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222214370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222214370">(Jan 10 2021 at 09:35)</a>:</h4>
<p>I've only ever used <code>leading_zeros</code> in a place where I wanted <code>ilog2</code>, so a general <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span> from me.</p>
<p>Now that <a href="https://doc.rust-lang.org/nightly/std/num/struct.NonZeroU32.html#method.leading_zeros"><code>NonZeroUN</code> has <code>leading_zeros</code></a>, maybe just put it on those to start?  That way you can avoid the whole <code>0</code>-vs-<code>-1</code>-vs-<code>None</code> conversation for log(0)...</p>



<a name="222214686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222214686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222214686">(Jan 10 2021 at 09:44)</a>:</h4>
<p>(And it should probably return <code>u32</code>, not <code>usize</code>, for consistency.  I totally get why you'd pick something other than <code>u32</code>, but I don't think <code>usize</code> is enough better to be worth being inconsistent.)</p>



<a name="222247904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222247904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222247904">(Jan 10 2021 at 23:31)</a>:</h4>
<p>I would <em>love</em> to have <code>ilog2</code> as well. I think someone just needs to post an updated PR that <em>only</em> includes <code>ilog2</code>.</p>



<a name="222247919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222247919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222247919">(Jan 10 2021 at 23:31)</a>:</h4>
<p>I've wanted that particular method a couple of times in the last few weeks.</p>



<a name="222248002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222248002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222248002">(Jan 10 2021 at 23:33)</a>:</h4>
<p>Out of curiosity, which behaviour did your situation want for ilog2(0), Josh?</p>



<a name="222259398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222259398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222259398">(Jan 11 2021 at 04:28)</a>:</h4>
<p>Bikeshed question: Do we call it <code>ilog2</code> or <code>highest_set_bit</code>?</p>



<a name="222259459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222259459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222259459">(Jan 11 2021 at 04:30)</a>:</h4>
<p>/me just now realized those are the same</p>



<a name="222259470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222259470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222259470">(Jan 11 2021 at 04:31)</a>:</h4>
<p>So for that reason alone I like highest_set_bit</p>



<a name="222262194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222262194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222262194">(Jan 11 2021 at 05:41)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> I'd like it to be called <code>ilog2</code>, because in practice what I tend to <em>want</em> (and what I've seen others want) is the integer log, not the highest set bit. And much like existing functions such as <code>leading_zeroes</code>, while it's possible to construct what you want, you have to think about it to figure out if it matches the semantics you want.</p>



<a name="222262305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222262305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222262305">(Jan 11 2021 at 05:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std/near/222248002">said</a>:</p>
<blockquote>
<p>Out of curiosity, which behaviour did your situation want for ilog2(0), Josh?</p>
</blockquote>
<p>For one of the cases, I had a semantic guarantee that the argument would never be 0. For the other, I didn't, but I had a check for zero in advance.</p>



<a name="222262333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222262333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222262333">(Jan 11 2021 at 05:45)</a>:</h4>
<p>Would a doc alias work in this case? Also, having <code>highest_set_bit</code> would allow for having <code>lowest_set_bit</code> as well; as well as <code>_unset_bit</code>.</p>



<a name="222262560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222262560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222262560">(Jan 11 2021 at 05:52)</a>:</h4>
<p><span class="user-mention" data-user-id="296643">@isHavvy</span> "highest set" and "lowest set" already more-or-less exist (as <code>trailing_zeros</code> and <code>leading_zeros</code>).</p>



<a name="222262572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222262572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222262572">(Jan 11 2021 at 05:53)</a>:</h4>
<p>The goal of having <code>ilog2</code> is specifically to have a function that's clearly "the integer log", not "equivalent to the integer log if you check the docs first".</p>



<a name="222262723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222262723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222262723">(Jan 11 2021 at 05:57)</a>:</h4>
<p>Fair enough.</p>



<a name="222262772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222262772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222262772">(Jan 11 2021 at 05:58)</a>:</h4>
<p>(And, for that matter, to be self-documenting for the next person who reads the code.)</p>



<a name="222262777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222262777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222262777">(Jan 11 2021 at 05:59)</a>:</h4>
<p>I'm glad that <code>leading_zeros</code> and <code>trailing_zeros</code> exist, though, because occasionally that <em>is</em> the function you want. And in practice I expect there to be one underlying implementation, and just a couple of functions that call it.</p>



<a name="222271404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222271404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222271404">(Jan 11 2021 at 08:45)</a>:</h4>
<p>My main concern with <code>ilog2</code> is that it's not clear if it's <code>log2</code> rounded up or down. Or what <code>ilog2(0)</code> even means. On the other hand <code>highest_set_bit</code>/<code>trailing_zeros</code>/<code>leading_zeros</code> have unambiguous semantics.</p>



<a name="222276325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222276325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222276325">(Jan 11 2021 at 09:43)</a>:</h4>
<p>My solution for the algebraics crate is to have separate <code>ceil_log2</code> and <code>floor_log2</code> functions: <a href="https://docs.rs/algebraics/0.2.0/algebraics/algebraic_numbers/struct.RealAlgebraicNumber.html#method.checked_floor_log2">https://docs.rs/algebraics/0.2.0/algebraics/algebraic_numbers/struct.RealAlgebraicNumber.html#method.checked_floor_log2</a></p>



<a name="222276549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222276549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222276549">(Jan 11 2021 at 09:46)</a>:</h4>
<p>see also the <a href="https://docs.rs/algebraics/0.2.0/algebraics/traits/trait.CeilLog2.html"><code>CeilLog2</code></a> and <a href="https://docs.rs/algebraics/0.2.0/algebraics/traits/trait.FloorLog2.html"><code>FloorLog2</code></a> traits</p>



<a name="222292965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222292965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222292965">(Jan 11 2021 at 12:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std/near/222262777">said</a>:</p>
<blockquote>
<p>I'm glad that <code>leading_zeros</code> and <code>trailing_zeros</code> exist, though, because occasionally that <em>is</em> the function you want. And in practice I expect there to be one underlying implementation, and just a couple of functions that call it.</p>
</blockquote>
<p>that sounds like you can add <code>doc(alias = "ilog2")</code> and get most of the benefit</p>



<a name="222303510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222303510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222303510">(Jan 11 2021 at 14:30)</a>:</h4>
<p>I can probably revive my PR adding <code>Integer::log</code> -- it was accepted, with all that's missing really is fixing a failing test on a platform which has a non-native float impl.</p>



<a name="222304031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222304031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222304031">(Jan 11 2021 at 14:34)</a>:</h4>
<p>[deleted]</p>



<a name="222325947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222325947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222325947">(Jan 11 2021 at 17:04)</a>:</h4>
<p>Okay, resurrected the log PR: <a href="https://github.com/rust-lang/rust/pull/80918">https://github.com/rust-lang/rust/pull/80918</a></p>



<a name="222358595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222358595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222358595">(Jan 11 2021 at 21:11)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std/near/222262305">said</a>:</p>
<blockquote>
<p>For one of the cases, I had a semantic guarantee that the argument would never be 0. For the other, I didn't, but I had a check for zero in advance.</p>
</blockquote>
<p>Interesting -- that gives extra support to the "just put it on <code>NonZeroU##</code>" approach.</p>



<a name="222400110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222400110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222400110">(Jan 12 2021 at 07:49)</a>:</h4>
<p>That would have been inconvenient.</p>



<a name="222400139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222400139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222400139">(Jan 12 2021 at 07:49)</a>:</h4>
<p>I had knowledge that it was non-zero, because I just calculated it, but it was still in a u64.</p>



<a name="222494901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222494901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222494901">(Jan 12 2021 at 21:09)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> it might have unambiguous semantics, but not obvious semantics, at least for me it requires thinking.</p>
<p>I think it's obvious that like all other integer operations(ie division) they are rounded down.</p>



<a name="222844869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Add%20integer%20log2%20function%20to%20std/near/222844869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Add.20integer.20log2.20function.20to.20std.html#222844869">(Jan 15 2021 at 11:17)</a>:</h4>
<p>(deleted)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>